<?php

namespace App\Trip\Orders\Traits;

use Exception;

trait ThrowErrorMessageTrait
{
    public string $error_msg  = '';
    public int    $error_code = 1;

    /**
     * @throws Exception
     */
    function throwErrorMessage(string $message, int $code = 1)
    {
        $this->setErrorCode($code);
        $this->setErrorMsg($message);
        throw new Exception($this->getErrorMsg(), $this->getErrorCode());
    }

    public function getErrorMsg(): string
    {
        return $this->error_msg;
    }

    public function setErrorMsg(string $message): void
    {
        $this->error_msg = $message;
    }

    public function getErrorCode(): int|string
    {
        return $this->error_code;
    }

    function setErrorCode(int $code): void
    {
        $code             = $code ?: 1;
        $this->error_code = $code;
    }
}